import sqlalchemy
import pandas as pd
from sqlalchemy import create_engine
import pymysql
print(sqlalchemy.__version__)
# 确保 SQLAlchemy 是2.0.36或更高
print(pymysql.__version__)
# 确保 PYMYSQL 是1.0.3 或更新
from sqlalchemy.types import *
from pandas.io import sql
df = pd.DataFrame({"班级":["一年级","二年级","三年级","四年级"],
                   "男生人数":[25,23,27,30],
                   "女生人数":[19,17,20,20]})
print(df)
engine = create_engine('mysql+pymysql://root:123456@127.0.0.1/python?charset=utf8mb4')
df.to_sql('students',con=engine,if_exists='replace',index=False)
print(pd.read_sql('students',con=engine))
#sql语句
#sql='内填sql语句'
#pd.read_sql(sql, engine)#输出